package com.ego.user.controller;

import com.ego.exception.EgoException;
import com.ego.exception.ExceptionEnum;
import com.ego.user.pojo.UserAndInfo;
import com.ego.user.service.UserAndInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/info")
@Slf4j
public class UserAndInfoController {


    @Autowired
    private UserAndInfoService userAndInfoService;

    @GetMapping("/getInfo")
    public ResponseEntity<UserAndInfo> getUserInfo(){
        return ResponseEntity.ok(userAndInfoService.getUserInfo());
    }

    @PutMapping("/updateInfo")
    public ResponseEntity<Void> updateInfo(@RequestBody UserAndInfo userAndInfo){
        int row = userAndInfoService.update(userAndInfo);
        if (row<=0){
            EgoException.error(log, ExceptionEnum.USER_INFO_UPDATE_EXCEPTION);
        }
        return ResponseEntity.ok().build();
    }
}
